<div id="tracking-content">
    <div id="tracking-left">
        <?php if ($this->ships->count() > 0): ?>
            <?php foreach ($this->ships as $ship): ?>
                <div class="tracking-ship-wrapper">
                    <div class="tracking-thumb">
                        <?php if ($ship['vessel_on_arrival']) : ?>
                            <img src="<?php echo UPLOAD_URL . $ship['vessel_on_arrival'] ?>" width="100%" height="100%">
                        <?php else: ?>
                            <img src="<?php echo $this->baseUrl() ?>/public/images/input_ship.jpg" width="100%" height="100%">
                        <?php endif; ?>
                    </div>
                    <div class="tracking-detail">
                        <h1 class='vessel_name'><?php echo $ship['vessel'] ?></h1>
                        <p>Principal: <?php echo $ship['fullname'] ?></p>
                        <p>Ref No.: <?php echo $ship['ref_no'] ?></p>
                        <p>Port: <?php echo $ship['port_name'] ?></p>
                        <p>Purpose of call: <?php echo $ship['purpose_of_call'] ?></p>
                        <p>ATA: <?php Core_Util::renderDate($ship['ata']) ?></p>
                        <p>ATS: <?php Core_Util::renderDate($ship['ats']) ?></p>
                        <br/>
                        <div class='wrap-tracking-button'>
                            <a href="<?php echo $this->baseUrl() ?>/service/detail/giid/<?php echo $ship['id'] ?>">
                                <span class="button">View detail</span>
                            </a>
                            <?php
                            if (!empty($this->session->user) &&
                                    ($this->session->user->role == Core_Role::ROLE_INPUT ||
                                    $this->session->user->role == Core_Role::ROLE_ADMIN)):
                                ?>
                                <a href="<?php echo $this->baseUrl() ?>/service/update/giid/<?php echo $ship['id'] ?>">
                                    <span class="button">Update</span>
                                </a>
                            <?php endif; ?>
                            <?php
                            if (!empty($this->session->user) &&
                                    $this->session->user->role == Core_Role::ROLE_ADMIN):
                                ?>
                                <a class="delete-gi" href="javascript:void(0)" name='<?php echo $ship['id'] ?>'>
                                    <span class="button">Delete</span>
                                </a>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
            <center>
                <div class="paging">
                    <?php echo $this->paginationControl($this->paginator, "Sliding", "/_partial/paginator.phtml") ?>
                </div>
            </center>
        <?php else: ?>
            There's not any ship
        <?php endif; ?>
    </div>
    <div class="tracking-right">
        <h1>Refine this search</h1>
        <form method='GET'>
            <div class="elements">
                <label for="ref_no">Ref No</label>
                <input type="text" class="refine" id="ref_no" name='ref_no' placeholder="Enter text..." value="<?php echo $this->filters['ref_no'] ?>"/>
            </div>            
            <div class="elements">
                <label for="vessel">Vessel</label>
                <input type="text" class="refine" id="vessel" placeholder="Enter text..." name="vessel" value="<?php echo $this->filters['vessel'] ?>"/>
            </div>
            <div class="elements">
                <label for="portofcall">Port of call</label>
                <select name="port_of_call" id="ddlOne">
                    <option value='0'>-- Select Port -- </option>
                    <?php foreach ($this->ports as $port): ?>
                        <option value="<?php echo $port->id ?>" <?php echo $this->filters['port_of_call'] == $port->id ? "selected" : "" ?>><?php echo $port['name'] ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="elements">
                <label for="ata">ATA</label>
                <input type="text" class="refine datetime" id="ata" placeholder="dd/mm/yy" name='ata'
                       value='<?php echo!empty($this->filters['ata']) ? Core_Util::renderDate($this->filters['ata']) : "" ?>'/>
            </div>
            <div class="elements">
                <label for="ats">ATS</label>
                <input type="text" class="refine datetime" id="ats" placeholder="dd/mm/yy" name='ats'
                       value='<?php echo!empty($this->filters['ats']) ? Core_Util::renderDate($this->filters['ats']) : "" ?>'/>
            </div>
            <div class='elements'>
                <input type="submit" class="submit" value="Search" style="margin-right:5%; float:right" />
            </div>
        </form>    
        <div style="clear: both;">&nbsp;</div>
    </div>
    <div style="clear: both;">&nbsp;</div>
</div>
<div id="confirm_dialog">
    Are you really sure you want to delete this. This operation can not be undone
</div>
<script src='<?php echo $this->baseUrl() ?>/public/js/tracking.js'></script>
<link rel='stylesheet' type='text/css' href='<?php echo $this->baseUrl() ?>/public/css/jquery-ui/jquery-ui-1.10.3.css'/>
<script src='<?php echo $this->baseUrl() ?>/public/js/jquery-ui-1.10.3.js'></script>
<style>
    .vessel_name {
        margin-bottom: 20px;
        color: #3b5998;
    }
</style>
<script>
    $(document).ready(function() {
        $("#confirm_dialog").dialog({
            modal: true,
            autoOpen: false,
            resizable: false,
            draggable: false
        })
        $(".delete-gi").click(function() {
            var giid = $(this).attr("name");
            $("#confirm_dialog").dialog('open');
            $("#confirm_dialog").dialog({
                buttons: {
                    "Yes": function() {
                        window.location = base_url + '/tracking/delete-service/giid/' + giid;
                    },
                    "No": function() {
                        $(this).dialog("close");
                    }
                }
            });
        })
    })
</script>